unit evolucaoidf_unt;

interface

uses
  Funcoes,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, IBCustomDataSet, IBQuery, TeEngine, Series, ExtCtrls,
  TeeProcs, Chart, DbChart, StdCtrls, Buttons, Grids, DBGrids;

type
  Tevolucaoidf_frm = class(TForm)
    IBQEvolucaoIDF: TIBQuery;
    dsEvolucaoIDF: TDataSource;
    IBQEvolucaoIDFDATAREGISTRO: TDateField;
    IBQEvolucaoIDFIDF: TIBBCDField;
    IBQEvolucaoIDFIDFA: TIBBCDField;
    Panel1: TPanel;
    btnFechar: TBitBtn;
    pnlResumoFinanceiro: TPanel;
    pnlGradeInformacoes: TPanel;
    dbgEvolucaoIDF: TDBGrid;
    dbgResumoFinanceiro: TDBGrid;
    grfResumoFinanceiroTotal: TDBChart;
    pnlEvolucaoIDF: TPanel;
    grfEvolucaoIDF: TDBChart;
    Series1: TLineSeries;
    Series2: TLineSeries;
    dsResumoFinanceiroTotal: TDataSource;
    IBQResumoFinanceiroTotal: TIBQuery;
    IBQResumoFinanceiroPerCapito: TIBQuery;
    dsResumoFinanceiroPerCapito: TDataSource;
    IBQResumoFinanceiro: TIBQuery;
    IBBCDField8: TIBBCDField;
    IBBCDField9: TIBBCDField;
    dsResumoFinanceiro: TDataSource;
    IBQResumoFinanceiroRENDAPERCAPTA: TIBBCDField;
    IBQResumoFinanceiroDESPESAPERCAPTA: TIBBCDField;
    Series3: TPieSeries;
    IBQResumoFinanceiroTotalDESCRICAO: TIBStringField;
    IBQResumoFinanceiroTotalVALOR: TIBBCDField;
    IBQResumoFinanceiroPerCapitoDESCRICAO: TIBStringField;
    IBQResumoFinanceiroPerCapitoVALOR: TIBBCDField;
    DBChart1: TDBChart;
    PieSeries1: TPieSeries;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure IBQEvolucaoIDFAfterOpen(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
    procedure btnFecharClick(Sender: TObject);
    procedure IBQResumoFinanceiroTotalAfterOpen(DataSet: TDataSet);
    procedure IBQResumoFinanceiroPerCapitoAfterOpen(DataSet: TDataSet);
    procedure IBQResumoFinanceiroAfterOpen(DataSet: TDataSet);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    procedure ProcessaMsg(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;

var
  evolucaoidf_frm: Tevolucaoidf_frm;

implementation

{$R *.dfm}

uses DMSistema_unt, DMDados_unt, principal_unt, cadastrodomicilios_unt;

procedure Tevolucaoidf_frm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
   evolucaoidf_frm := nil;
   Action := caFree;
end;

procedure Tevolucaoidf_frm.IBQEvolucaoIDFAfterOpen(DataSet: TDataSet);
begin
   with IBQEvolucaoIDF do
   begin
      try
         FetchAll;
         First;
      except
      end;
   end;
end;

procedure Tevolucaoidf_frm.FormCreate(Sender: TObject);
begin
   with IBQEvolucaoIDF do
   begin
      try
         Screen.Cursor := crSQLWait;
         try
            Close;
            ParamByName('IDDOMICILIO').AsInteger := DMDados_frm.IBDSDomicilioIDDOMICILIO.Value;
            Prepare;
            Open;
         except
         end;
      finally
         Screen.Cursor := crDefault;
      end;
   end;
   with IBQResumoFinanceiro do
   begin
      try
         Screen.Cursor := crSQLWait;
         try
            Close;
            ParamByName('IDDOMICILIO').AsInteger := DMDados_frm.IBDSDomicilioIDDOMICILIO.Value;
            Prepare;
            Open;
         except
         end;
      finally
         Screen.Cursor := crDefault;
      end;
   end;
   with IBQResumoFinanceiroTotal do
   begin
      try
         Screen.Cursor := crSQLWait;
         try
            Close;
            ParamByName('IDDOMICILIO').AsInteger := DMDados_frm.IBDSDomicilioIDDOMICILIO.Value;
            Prepare;
            Open;
         except
         end;
      finally
         Screen.Cursor := crDefault;
      end;
   end;
   with IBQResumoFinanceiroPerCapito do
   begin
      try
         Screen.Cursor := crSQLWait;
         try
            Close;
            ParamByName('IDDOMICILIO').AsInteger := DMDados_frm.IBDSDomicilioIDDOMICILIO.Value;
            Prepare;
            Open;
         except
         end;
      finally
         Screen.Cursor := crDefault;
      end;
   end;
end;

procedure Tevolucaoidf_frm.btnFecharClick(Sender: TObject);
begin
   Close;
end;

procedure Tevolucaoidf_frm.IBQResumoFinanceiroTotalAfterOpen(
  DataSet: TDataSet);
begin
   with IBQResumoFinanceiroTotal do
   begin
      try
         FetchAll;
         First;
      except
      end;
   end;
end;

procedure Tevolucaoidf_frm.IBQResumoFinanceiroPerCapitoAfterOpen(DataSet: TDataSet);
begin
   with IBQResumoFinanceiroPerCapito do
   begin
      try
         FetchAll;
         First;
      except
      end;
   end;
end;

procedure Tevolucaoidf_frm.IBQResumoFinanceiroAfterOpen(DataSet: TDataSet);
begin
   with IBQResumoFinanceiro do
   begin
      try
         FetchAll;
         First;
      except
      end;
   end;
end;

procedure Tevolucaoidf_frm.ProcessaMsg(var Msg: TMsg;
  var Handled: Boolean);
begin
   if Msg.message = WM_KEYDOWN then
      if not (Screen.ActiveControl is TCustomMemo) and not (Screen.ActiveControl is TButtonControl) then
      begin
         if not (Screen.ActiveControl is TCustomControl) then
         begin
            if Msg.wParam = VK_Down then Msg.wParam := VK_Tab;
            if Msg.wParam = VK_UP then
            begin
               Msg.wParam := VK_CLEAR;
               Screen.ActiveForm.Perform(WM_NextDlgCtl,1,0);
            end;
         end;
         if Msg.wParam = VK_Return then Msg.wParam := VK_Tab;
      end;
end;

procedure Tevolucaoidf_frm.FormShow(Sender: TObject);
begin
   Application.OnMessage := ProcessaMsg;
end;

end.

